import kinterbasdb
import time, calendar, datetime, csv

#f1 = open('/home/cbe/.gvfs/bsg on 169.229.130.74/New York Times/Analysis/nytDataGaps4.csv', 'wb')
#testsout = csv.writer(f1,dialect='excel') 

con = kinterbasdb.connect (host = 'localhost', user = 'sysdba', password = 'G3ccFoUw', database = '/home/cbe/fbdata/NY Times/20120111facsdb.fdb')
cursor = con.cursor()        
cursor.execute ("SELECT datetime_stamp FROM data where datetime_stamp > '2011-11-04 00:00:00' order by datetime_stamp asc;")
data = cursor.fetchall()

#print calendar.timegm(data[1][3].utctimetuple()) - calendar.timegm(data[2][3].utctimetuple())
for x in xrange(len(data)):
    if x > 0:
        if (calendar.timegm(data[x][0].utctimetuple()) - calendar.timegm(data[x-1][0].utctimetuple())) > 300:
            print data[x-1][0], data[x][0]
            #testsout.writerow([data[x-1][0], data[x][0]])
#data = cursor.fetchmany(size=10)
#print calendar.timegm(data[0][3].utctimetuple())
#print (time.gmtime(data[1][3]) - time.gmtime(data[1][3]))
#data = range(10000)
#w = 0
#while len(data) > 9999:
#    data = cursor.fetchmany(size=10000)
#    r = 0
#    print (len(data)+(w*10000)), 'records read'
#    w += 1
#    for row in data:
#        motename = int(data[r][0])
#       channel1 = data[r][1]
#        channel2 = data[r][2]
#        motetime = calendar.timegm(data[r][3].utctimetuple()) + 3600*7
#        r += 1
cursor.close()  